import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 * Created by loyee on 16-3-9.
 */
public class Main {

    public static void main(String[] str) throws DocumentException, ParserConfigurationException, IOException, SAXException {
        SAXReader saxReader = new SAXReader();
        Document doc = saxReader.read(new File("/home/loyee/work/sdk_all/conch-android/android-frame/build/outputs/lint-results-debug.xml"));
        Element root = doc.getRootElement();
        List childList = root.elements();
        System.out.println("一共多少issues:" + childList.size());
        int size = childList.size();
        for (int i = 0; i < size; i++) {
            Element element = (Element) childList.get(i);
            String name = element.getName();
            String id = element.attributeValue("id");
            if (id.equals("UnusedResources")) {
                Element location = element.element("location");
                String filePath = location.attributeValue("file");
                if (filePath.endsWith("strings.xml") ||
                        filePath.endsWith("colors.xml") ||
                        filePath.endsWith("styles.xml") ||
                        filePath.endsWith("build.gradle") ||
                        filePath.endsWith("dimens.xml")) {
                    continue;
                } else {
                    System.out.println("i=:" + i + "   delete " + filePath);
                    File file = new File(filePath);
                    if(file.exists()) {
                        file.delete();
                    }
                }
            }
        }
    }
}
